#pragma once

#include <widgets/KeySearchWidget.h>
#include <bondlib/BondInfo.h>
#include <map>
#include <mutex>
#include <vector>

class IssuerSearchEngine : public IKeySearchEngine
{
public:
	enum eIssuerFlag {
		issuerNormal = 0,
		issuerAbsSeries,
		issuerAbsFinancier,
		issuerUnderwriter,
		issuerGuarantor
	};

	virtual void search(int serialNum, const QString& key) override;
	virtual void setUserData(int userdata) override;
	virtual void setResultCallback(std::function<void(int, QJsonArray)> fun) override;
	virtual void onResultSelected(const QString& key) override;

protected:
	void doSearch(int serialNum, const QString& key);
	bool isMatch(const CBondInfo& info, const char* text, int len, bool bIsAllNumber);

protected:
	std::function<void(int, QJsonArray)> m_fun = nullptr;
	int				m_userdata = 0;
	volatile int	m_curSearchSerialNum = 0;
	std::mutex		m_lock;
};
